{extend name="public/base" /}
{block name='body'}
<div class="layui-container fly-marginTop">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <!--<div class="fly-none">没有权限</div>-->
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">分享资源<!-- 编辑帖子 --></li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form">
                            <div class="layui-row layui-col-space15 layui-form-item">
                                <div class="layui-col-md3">
                                    <label class="layui-form-label">所在分类</label>
                                    <div class="layui-input-block">
                                        <select lay-verify="required" name="FK_ResourceCategoryGuid"
                                                lay-filter="column">
                                            <option></option>
                                            {volist name='cats' id='cat'}
                                            <option value="{$cat.PK_ResourceCategoryGuid}">{$cat.Name}</option>
                                            {/volist}
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md9">
                                    <label for="L_title" class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_title" name="Title" required lay-verify="required"
                                               autocomplete="off" class="layui-input">
                                        <!-- <input type="hidden" name="id" value="{{d.edit.id}}"> -->
                                    </div>
                                </div>
                            </div>
                            <div class="layui-row layui-col-space15 layui-form-item" id="LAY_quiz">
                                <div class="layui-col-md4">
                                    <label class="layui-form-label">资源类型</label>
                                    <div class="layui-input-block">
                                        <select name="restype" lay-filter="restype">
                                            <option></option>
                                            <option value="pan-share">网盘资源(百度网盘等)</option>
                                            <option value="e-share">实体资源(用户自行上传)</option>
                                            <option value="u-share">URL资源(第三方资源)</option>
                                            <option value="t-share">文本资源(用户个人感想)</option>
                                        </select>
                                    </div>
                                </div>

                                <!--网盘分享开始-->
                                <div class="layui-col-md6 layui-hide" restype="pan-share">
                                    <label class="layui-form-label" for="L_version">网盘地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" value="" name="panurl" autocomplete="off"
                                               class="layui-input" placeholder="网盘地址,带http或https的地址">
                                    </div>
                                </div>
                                <div class="layui-col-md2 layui-hide" restype="pan-share">
                                    <label class="layui-form-label" for="L_browser">分享密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_browser" value="" name="panpwd"
                                               placeholder="密码" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                                <!--网盘分享结束-->

                                <!--实体资源-->
                                <div class="layui-col-md8 layui-hide" restype="e-share">
                                    <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件
                                    </button>
                                </div>

                                <!--URL资源-->
                                <div class="layui-col-md8 layui-hide" restype="u-share">
                                    <label class="layui-form-label" for="L_version">URL地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L" value="" name="weburl" autocomplete="off"
                                               class="layui-input" placeholder="请输入完整的url地址">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <textarea id="L_content" name="Desc" required lay-verify="required"
                                              placeholder="详细描述" class="layui-textarea fly-editor"
                                              style="height: 260px;"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">所需金币</label>
                                    <div class="layui-input-inline" style="width: 190px;">
                                        <select name="Price">
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                        </select>
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">分享后无法修改金币</div>
                                </div>

                                <!--验证码-->
                                <div class="layui-form-item">
                                    <label for="L_vercode" class="layui-form-label">验证码</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="L_vercode" name="vercode" required lay-verify="required"
                                               placeholder="填写验证码" autocomplete="off" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid">
                                        <span style="color: #c00;"><div class="sw-verify-img"><img
                                                src="{:url('base/vercode','id=share')}" alt="" onclick="this.src=this.src+'?'+Math.random()"></div></span>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn" lay-filter="share" lay-submit>立即发布</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {/block}
    {block name='script'}
    <script>
        layui.use(['form', 'jquery', 'layer', 'upload'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.jquery;
            var upload = layui.upload;


            /**
             * 资源类别选择
             */
            form.on('select(restype)', function (data) {
                var val = data.value;//当前选中的资源类型的值
                var sels = [
                    'pan-share',
                    'e-share',
                    'u-share',
                    't-share'
                ];
                for (var i = 0; i < sels.length; i++) {
                    $("div[restype='" + sels[i] + "']").addClass('layui-hide');
                }
                ;
                $("div[restype='" + val + "']").removeClass('layui-hide');

            });


            /**
             * 提交资源
             */
            form.on('submit(share)', function (data) {
                var resData = data.field;
                var restype = resData.restype;
                var vercode = resData.vercode;
                $.post("{:url('base/checkVercode')}", {"code": vercode, "id": "share"}, function (res) {
                    if (res.errno === 0) {
                        //验证码正确
                        var typeObj = {
                            'pan-share': '网盘资源',
                            'e-share': '实体资源',
                            'u-share': 'URL资源',
                            't-share': '文本资源'
                        };
                        resData.type = typeObj[restype];
                        switch (restype) {
                            case 'pan-share': {
                                resData.type_value = resData.panurl + '-' + resData.panpwd;
                            }
                                break;
                            case 'e-share': {
                                //todo 实体资源地址
                                resData.type_value = '实体资源地址';
                            }
                                break;
                            case 'u-share': {
                                resData.type_value = resData.weburl;
                            }
                                break;
                            case 't-share':
                                resData.type_value = '';
                                break;
                        }

                        delete(resData['panurl']);
                        delete(resData['panpwd']);
                        delete(resData['weburl']);
                        delete(resData['restype']);
                        $.post("{:url('user/share')}", resData, function (res) {
                            console.log(res);
                        })

                    } else {
                        //验证码错误
                        return layer.msg('验证码错误');
                    }
                });

            })

        });

    </script>
    {/block}